layui.use(['layer','form','table','element'],function () {
    var layer = layui.layer
        ,form = layui.form
        ,table =layui.table
        ,element = layui.element;


    //初始化数据表格
     table.render({
         elem:"#data"
         ,height: 340
         ,url:"/driver/getButieData"
         ,cellMinWidth: 80
         ,cols: [[
              {field:'id',width:60,title: 'ID', sort: true}
             ,{field:'name', title: '补贴种类',width: 180}
             ,{field:'amount', width: 180   , title: '补贴金额'}
             ,{field:'showCreateTime',width:110,title: '创建时间',sort: true}
             ,{field:'',width:170,title: '操作',toolbar: '#barDemo'}
         ]]
         ,page:true
     });


     //监听工具条
     table.on('tool(dataTable)',function (obj) {
         var data = obj.data;
         if(obj.event == 'pay'){

             //支付
             parent.layui.element.tabAdd('tabs',{
                 title:"支付",
                 content:"<iframe  src='/driver/toPay?id="+data.id+"&type=1'  frameborder='0'  style='width:100%;height: 100%'></iframe>",
                 id:"toPayView"
             });
             rightMenu();
             iframeWH();
             parent.layui.element.tabChange('tabs','toPayView');

         }
     });


    $("#payBtn").bind("click",function () {
        alert("hello");
    })

    function rightMenu(){

        $(".layui-tab-title li",window.parent.document).on("contextmenu",function (e) {
            var rightmenu = $(".rightmenu",window.parent.document);
            rightmenu.find("li").attr('data-id',$(this).attr("lay-id"));
            l = e.clientX;
            t = e.clientY;
            rightmenu.css({ left:l, top:t}).show();
            return false;
        });
        //左键点击隐藏
        $("body,.layui-tab-title li",window.parent.document).click(function(){
            $(".rightmenu").hide();
        });

    }

    function iframeWH(){
        var H = $(window).height();
        $("iframe",window.parent.document).css("height",H+"px");
    }
     
     //搜索
    $("#search").on("click",function () {
        table.reload("data",{
            page:{
                curr:1
            }
            ,where:{
                title:$("#title").val(),
                typeId:$("#type").val(),
                labelId:$("#label").val(),
                commented:$("#commented").val()
            }
        })
    });;

    $("#add").on("click",function () {

        parent.layui.element.tabAdd('tabs',{
            title:"免费项目新增",
            content:"<iframe  src='/admin/project/freeToAdd'  frameborder='0'  style='width:100%;height: 100%'></iframe>",
            id:"free_project_add"
        });
        rightMenu();
        iframeWH();
        parent.layui.element.tabChange('tabs','free_project_add');


    })


});
